import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_state_manager/get_state_manager.dart';

import '../controller/timer_controller.dart';

class TimerWidget extends StatelessWidget {
  final String tag;
  final int seconds;
  final Color color;
  final Function()? callback;

  const TimerWidget({
    super.key,
    required this.tag,
    required this.seconds,
    required this.color,
    this.callback,
  });

  @override
  Widget build(BuildContext context) {
    final timerController = Get.put(
        TimerController(
          seconds,
          callback,
        ),
        tag: tag);
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 3),
      decoration: BoxDecoration(
        color: Colors.transparent, //设置背景颜色
        border: Border.all(color: color, width: 1.0, style: BorderStyle.solid), borderRadius: const BorderRadius.all(Radius.circular(3)),
      ),
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          Icon(Icons.watch_later, size: 11, color: color),
          const SizedBox(
            width: 3,
          ),
          GetBuilder<TimerController>(
            tag: tag,
            builder: (controller) {
              return Text(
                controller.time.value,
                style: TextStyle(
                  fontSize: 11,
                  color: color,
                ),
              );
            },
          ),
        ],
      ),
    );
  }
}
